<template>
	<!-- 当mescroll-body写在子组件时,父页面需引入mescroll-comp.js的mixins -->
	<mescroll-body ref="mescrollRef" :top="offsetTop" @init="mescrollInit" @down="downCallback" @up="upCallback">
		<!-- 数据列表 -->
		<address-item :list="addressList" :chooseFlag="chooseFlag" :prescriptionId="prescriptionId"
			:hospTotalPrice="hospTotalPrice" :drugsList="drugsList" :action="action" :orderFlag="orderFlag" :orderId="orderId"
			:hospId="hospId" :addressJson="addressJson"></address-item>
	</mescroll-body>
</template>

<script>
import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
import mRequest from "@/api/home"
import addressItem from './address-item/address-item.vue'
import hccmStore from "@/common/hccm-store.js"
export default {
	mixins: [MescrollMixin], // 使用mixin
	components: { addressItem },
	props: {
		chooseFlag: {
			type: Boolean,
			default: false,
		},
		orderFlag: {
			type: Boolean,
			default: false,
		},
		addressJson: {
			type: String,
			default: {},
		},
		drugsList: {
			type: String,
			default: '',
		},
		action: {
			type: String,
			default: '',
		},
		prescriptionId: {
			type: String,
			default: '',
		},
		hospTotalPrice: {
			type: String,
			default: '',
		},
		orderId: {
			type: String,
			default: '',
		},
		hospId: {
			type: String,
			default: '',
		},
	},
	data() {
		return {
			offsetTop: 0, //安全高度
			userInfo: hccmStore.getUser(),
			addressList: []
		}
	},
	methods: {
		/*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
		upCallback(page) {
			//联网加载数据
			let params = {
				patientMobile: hccmStore.getUserPhone(),
				currentPage: page.num,
				pageSize: page.size
			}
			mRequest.getAddress(params).then(
				res => {
					console.log(this.addressList)
					if (page.num == 1) this.addressList = []; //如果是第一页需手动制空列表
					this.addressList = this.addressList.concat(res.responseData); //追加新数据
					this.mescroll.endSuccess(res.responseData.length)
					this.mescroll.endBySize(this.addressList.length, Number(this.addressList.length) + 10); //
				},
				error => {
					this.mescroll.endErr();
				}
			)
		}
	}
}
</script>
